package main

import (
	"fmt"

	"gitcode.com/openHiTLS/go_sdk_demo/hitls/crypto/hmac"
)

func main() {
	key := make([]byte, 32)
	for i := 0; i < 32; i += 1 {
		key[i] = byte(i)
	}
	fmt.Println("---------- hmac demo ----------")
	hmac.ClientToServer = make(chan []byte)
	hmac.ServerToClient = make(chan []byte)
	defer close(hmac.ClientToServer)
	defer close(hmac.ServerToClient)
	var ret [2]chan error
	hmac.WG.Add(2)
	go func() {
		ret[0] <- hmac.Client(key, hmac.HMAC_SHA256)
	}()
	go func() {
		ret[1] <- hmac.Server(key, hmac.HMAC_SHA256)
	}()
	hmac.WG.Wait()
	for _, err := range ret {
		if err != nil {
			fmt.Printf("%v", err)
			panic("hmac error")
		}
	}
	fmt.Println("Everything is okay")
}
